```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Stream 学习指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #2d3748;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #1a202c;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #f8fafc;
            border-left: 4px solid #4f46e5;
            font-family: 'Courier New', Courier, monospace;
        }
        .highlight {
            position: relative;
        }
        .highlight::before {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(79, 70, 229, 0.2);
            z-index: -1;
            transform: skewY(-1deg);
        }
        .divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <div class="flex justify-center mb-6">
                <span class="inline-flex items-center px-4 py-2 rounded-full bg-indigo-600 text-white text-sm font-medium">
                    <i class="fas fa-code mr-2"></i> Java 8+
                </span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Java Stream API 完全指南</h1>
            <p class="text-xl md:text-2xl text-indigo-100 max-w-3xl mx-auto mb-8">
                掌握现代Java集合处理的艺术 - 从基础到高级技巧，构建高效、优雅的数据处理流水线
            </p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#intro" class="px-6 py-3 bg-white text-indigo-600 rounded-lg font-medium hover:bg-opacity-90 transition duration-200">
                    <i class="fas fa-book-open mr-2"></i> 开始学习
                </a>
                <a href="#examples" class="px-6 py-3 bg-indigo-700 text-white rounded-lg font-medium hover:bg-indigo-800 transition duration-200">
                    <i class="fas fa-laptop-code mr-2"></i> 实战示例
                </a>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Introduction Section -->
        <section id="intro" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-info-circle text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">Stream 简介</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <p class="text-lg text-gray-700 mb-6">
                    在 Java 8 中引入了 Stream API，它是一种用于处理集合数据的抽象概念，提供了一种流畅的、函数式的处理集合元素的方式。Stream API 可以让我们更加简洁、高效地处理集合数据，同时也提高了代码的可读性和可维护性。
                </p>
                
                <div class="grid md:grid-cols-2 gap-8 my-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">什么是 Stream？</h3>
                        <p class="text-gray-700">
                            Stream 是一个用来处理集合数据的工具，它可以让我们以一种流水线式的方式对集合进行操作。Stream API 提供了一组丰富的中间操作和终端操作，可以让我们以函数式的风格对集合进行筛选、转换、排序等操作，从而避免了传统的迭代式处理方式。
                        </p>
                    </div>
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Stream 的作用和优势</h3>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><span class="font-medium">简化代码</span>：提供更简洁、清晰的方式来处理集合数据</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><span class="font-medium">提高效率</span>：使用惰性求值和并行处理，更高效处理大规模数据</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><span class="font-medium">支持并行处理</span>：充分利用多核处理器的性能</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="mt-8 overflow-hidden rounded-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711334182917-5aaddbf1-ebb6-4353-9644-81cbf5196be6.png" alt="Stream API 示意图" class="w-full h-auto rounded-lg">
                </div>
            </div>
        </section>

        <!-- Creation Section -->
        <section id="creation" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-plus-circle text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">创建 Stream</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <p class="text-lg text-gray-700 mb-8">
                    在 Java 中，可以通过多种方式来创建 Stream，包括集合、数组、文件等。以下是常见的创建方式：
                </p>

                <div class="grid md:grid-cols-2 gap-8">
                    <!-- 从集合创建 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-list-ul mr-2"></i> 从集合创建
                        </h3>
                        <p class="text-gray-700 mb-4">
                            可以通过集合的 <code class="bg-gray-200 px-2 py-1 rounded">stream()</code> 方法来创建 Stream
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;String&gt; list = Arrays.asList("apple", "banana", "orange");<br>
                                Stream&lt;String&gt; stream = list.stream();
                            </code>
                        </div>
                    </div>

                    <!-- 从数组创建 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-brackets-curly mr-2"></i> 从数组创建
                        </h3>
                        <p class="text-gray-700 mb-4">
                            使用 <code class="bg-gray-200 px-2 py-1 rounded">Arrays.stream()</code> 方法从数组中创建 Stream
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                String[] array = {"apple", "banana", "orange"};<br>
                                Stream&lt;String&gt; stream = Arrays.stream(array);
                            </code>
                        </div>
                    </div>

                    <!-- Stream.of() -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-cube mr-2"></i> 使用 Stream.of()
                        </h3>
                        <p class="text-gray-700 mb-4">
                            使用 <code class="bg-gray-200 px-2 py-1 rounded">Stream.of()</code> 方法直接传入多个元素来创建 Stream
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                Stream&lt;String&gt; stream = Stream.of("apple", "banana", "orange");
                            </code>
                        </div>
                    </div>

                    <!-- Stream.generate() -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-infinity mr-2"></i> 使用 Stream.generate()
                        </h3>
                        <p class="text-gray-700 mb-4">
                            创建一个无限长度的 Stream
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                Stream&lt;Integer&gt; stream = Stream.generate(() -> 1);
                            </code>
                        </div>
                    </div>

                    <!-- Stream.iterate() -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-sync-alt mr-2"></i> 使用 Stream.iterate()
                        </h3>
                        <p class="text-gray-700 mb-4">
                            创建一个无限长度的 Stream，每个元素都是前一个元素加 2
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                Stream&lt;Integer&gt; stream = Stream.iterate(0, n -> n + 2);
                            </code>
                        </div>
                    </div>

                    <!-- Files.lines() -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-file-alt mr-2"></i> 使用 Files.lines()
                        </h3>
                        <p class="text-gray-700 mb-4">
                            从文件中逐行读取数据，创建一个包含文件内容的 Stream
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                Path path = Paths.get("file.txt");<br>
                                Stream&lt;String&gt; lines = Files.lines(path);
                            </code>
                        </div>
                    </div>
                </div>

                <div class="mt-8 overflow-hidden rounded-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711334296178-3b6494e0-bb3b-42e7-a754-13332013c78d.png" alt="创建Stream的方式" class="w-full h-auto rounded-lg">
                </div>
            </div>
        </section>

        <!-- Operations Section -->
        <section id="operations" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-cogs text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">Stream 操作</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <p class="text-lg text-gray-700 mb-8">
                    Stream 提供了丰富的操作方法来对数据进行过滤、映射、排序、聚合等操作。这些操作分为中间操作和终端操作两种类型。
                </p>

                <div class="grid md:grid-cols-2 gap-8 mb-8">
                    <!-- 过滤操作 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-filter mr-2"></i> 过滤操作
                        </h3>
                        <p class="text-gray-700 mb-4">
                            通过 <code class="bg-gray-200 px-2 py-1 rounded">filter()</code> 方法筛选出符合条件的元素
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4, 5);<br>
                                numbers.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.filter(n -> n % 2 == 0)<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println); // 输出偶数
                            </code>
                        </div>
                    </div>

                    <!-- 映射操作 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-project-diagram mr-2"></i> 映射操作
                        </h3>
                        <p class="text-gray-700 mb-4">
                            通过 <code class="bg-gray-200 px-2 py-1 rounded">map()</code> 方法将每个元素映射成另一个元素
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;String&gt; words = Arrays.asList("apple", "banana", "orange");<br>
                                words.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.map(String::toUpperCase)<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println);
                            </code>
                        </div>
                    </div>

                    <!-- 排序操作 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-sort-amount-down mr-2"></i> 排序操作
                        </h3>
                        <p class="text-gray-700 mb-4">
                            通过 <code class="bg-gray-200 px-2 py-1 rounded">sorted()</code> 方法对元素进行排序
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;Integer&gt; numbers = Arrays.asList(3, 1, 4, 2, 5);<br>
                                numbers.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.sorted()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println);
                            </code>
                        </div>
                    </div>

                    <!-- 聚合操作 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-calculator mr-2"></i> 聚合操作
                        </h3>
                        <p class="text-gray-700 mb-4">
                            通过 <code class="bg-gray-200 px-2 py-1 rounded">reduce()</code> 方法将所有元素进行聚合
                        </p>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4, 5);<br>
                                int sum = numbers.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.reduce(0, Integer::sum); // 求和
                            </code>
                        </div>
                    </div>
                </div>

                <div class="mt-8 overflow-hidden rounded-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711334356199-26ad968b-6dad-4a84-ac9d-14d19b48076c.png" alt="Stream操作示意图" class="w-full h-auto rounded-lg">
                </div>
            </div>
        </section>

        <!-- Parallel Stream Section -->
        <section id="parallel" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-sliders-h text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">并行流和串行流</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <p class="text-lg text-gray-700 mb-8">
                    Stream 可以通过<strong class="text-indigo-600">串行流</strong>（Sequential Stream）和<strong class="text-indigo-600">并行流</strong>（Parallel Stream）两种方式进行处理，各有适用场景。
                </p>

                <div class="grid md:grid-cols-2 gap-8 mb-8">
                    <div>
                        <h3 class="text-2xl font-semibold mb-4 text-indigo-600">串行流（Sequential Stream）</h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>Stream 默认的流，按顺序处理每个元素</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>每个操作都是依次执行</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>适合数据量较小或对计算顺序有要求的情况</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-2xl font-semibold mb-4 text-indigo-600">并行流（Parallel Stream）</h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>通过 <code class="bg-gray-200 px-1 py-0.5 rounded">parallel()</code> 方法将串行流转换为并行流</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>将流中的元素分成多个部分，在多个线程中同时处理</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>适合大规模数据处理和复杂的计算任务</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r mb-8">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-blue-500 text-xl"></i>
                        </div>
                        <div class="ml-3">
                            <h4 class="text-lg font-medium text-blue-700">如何将串行流转换为并行流？</h4>
                            <div class="mt-2 text-blue-700">
                                <p class="mb-2">通过 <code class="bg-blue-100 px-2 py-1 rounded">parallel()</code> 方法转换：</p>
                                <div class="code-block p-4 rounded">
                                    <code>
                                        List&lt;Integer&gt; list = Arrays.asList(1, 2, 3, 4, 5);<br>
                                        Stream&lt;Integer&gt; parallelStream = list.parallelStream();
                                    </code>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="grid md:grid-cols-2 gap-8">
                    <div class="bg-green-50 border-l-4 border-green-500 p-4 rounded-r">
                        <h4 class="text-lg font-semibold text-green-700 mb-2">并行流的优势</h4>
                        <ul class="space-y-2 text-green-700">
                            <li class="flex items-start">
                                <i class="fas fa-bolt mt-1 mr-2"></i>
                                <span>提高性能：充分利用多核处理器</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-tachometer-alt mt-1 mr-2"></i>
                                <span>适用于大规模数据：更快完成任务</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 rounded-r">
                        <h4 class="text-lg font-semibold text-yellow-700 mb-2">并行流注意事项</h4>
                        <ul class="space-y-2 text-yellow-700">
                            <li class="flex items-start">
                                <i class="fas fa-exclamation-triangle mt-1 mr-2"></i>
                                <span>容易出错：可能引发线程安全问题</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-memory mt-1 mr-2"></i>
                                <span>内存消耗较大：需要额外线程和同步机制</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="mt-8 overflow-hidden rounded-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711335141802-3ada1c3a-fdff-4b92-a3a5-4dd10526f5ec.png" alt="并行流与串行流比较" class="w-full h-auto rounded-lg">
                </div>
            </div>
        </section>

        <!-- Advanced Section -->
        <section id="advanced" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-star text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">Stream API 的扩展</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <div class="grid md:grid-cols-2 gap-8 mb-8">
                    <!-- 延迟执行 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-clock mr-2"></i> 延迟执行
                        </h3>
                        <p class="text-gray-700">
                            Stream 中的操作都是延迟执行的，只有在终止操作调用时才会触发中间操作的执行。这种延迟执行的特性可以提高效率，避免不必要的计算和资源浪费。
                        </p>
                    </div>

                    <!-- 收集器 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-box-open mr-2"></i> 收集器（Collector）
                        </h3>
                        <p class="text-gray-700">
                            Stream 提供了丰富的收集器来将流中的元素汇总、转换成其他形式。常见收集器包括 <code class="bg-gray-200 px-1 py-0.5 rounded">toList()</code>、<code class="bg-gray-200 px-1 py-0.5 rounded">toSet()</code>、<code class="bg-gray-200 px-1 py-0.5 rounded">toMap()</code> 等。
                        </p>
                    </div>

                    <!-- Optional -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-question-circle mr-2"></i> Optional 类型
                        </h3>
                        <p class="text-gray-700">
                            Optional 类型可以避免空指针异常，并提供了一些便捷的方法来处理可能为空的值。在 Stream 中使用 Optional 类型可以有效地处理可能为空的元素，提高代码的健壮性。
                        </p>
                    </div>

                    <!-- 并行流优化 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                            <i class="fas fa-tachometer-alt mr-2"></i> 并行流的性能优化
                        </h3>
                        <p class="text-gray-700">
                            在使用并行流时，应注意避免共享可变状态和数据源的操作，以免引发竞态条件和线程安全问题。可以使用并行流提供的 <code class="bg-gray-200 px-1 py-0.5 rounded">reduce()</code>、<code class="bg-gray-200 px-1 py-0.5 rounded">collect()</code> 等方法来保证线程安全。
                        </p>
                    </div>
                </div>

                <div class="mt-8 overflow-hidden rounded-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711335529448-2dd5b8a0-a175-42e9-8c5e-e54ccaad4702.png" alt="Stream API扩展" class="w-full h-auto rounded-lg">
                </div>
            </div>
        </section>

        <!-- Examples Section -->
        <section id="examples" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-laptop-code text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">Stream 示例</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <div class="grid md:grid-cols-2 gap-8">
                    <!-- 示例1 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">
                            1. 筛选符合条件的元素
                        </h3>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;String&gt; names = Arrays.asList("Alice", "Bob", "Charlie", "David");<br><br>
                                // 找出长度大于4的名字并输出<br>
                                names.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.filter(name -> name.length() > 4)<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println);
                            </code>
                        </div>
                    </div>

                    <!-- 示例2 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">
                            2. 对元素进行转换和映射
                        </h3>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;String&gt; names = Arrays.asList("Alice", "Bob", "Charlie", "David");<br><br>
                                // 将名字转换为大写并输出<br>
                                names.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.map(String::toUpperCase)<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println);
                            </code>
                        </div>
                    </div>

                    <!-- 示例3 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">
                            3. 对元素进行排序
                        </h3>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;String&gt; names = Arrays.asList("Alice", "Bob", "Charlie", "David");<br><br>
                                // 按照字母顺序排序并输出<br>
                                names.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.sorted()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.forEach(System.out::println);
                            </code>
                        </div>
                    </div>

                    <!-- 示例4 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">
                            4. 汇总和统计
                        </h3>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4, 5);<br><br>
                                // 计算元素总和<br>
                                int sum = numbers.stream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.reduce(0, Integer::sum);<br>
                                System.out.println("总和：" + sum);
                            </code>
                        </div>
                    </div>

                    <!-- 示例5 -->
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">
                            5. 并行流的使用
                        </h3>
                        <div class="code-block p-4 rounded mb-4">
                            <code>
                                List&lt;Integer&gt; numbers = Arrays.asList(1, 2, 3, 4, 5);<br><br>
                                // 使用并行流计算元素总和<br>
                                int sum = numbers.parallelStream()<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;.reduce(0, Integer::sum);<br>
                                System.out.println("总和：" + sum);
                            </code>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Considerations Section -->
        <section id="considerations" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-exclamation-triangle text-indigo-500 text-2xl mr-4"></i>
                <h2 class="text-3xl font-bold">Stream 注意事项</h2>
            </div>
            <div class="bg-white rounded-xl p-8 card-hover">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-red-100 rounded-full p-2">
                                    <i class="fas fa-ban text-red-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">避免修改源数据</h4>
                                    <p class="mt-1 text-gray-600">Stream 操作应该是无状态的，不应该修改原始数据</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-yellow-100 rounded-full p-2">
                                    <i class="fas fa-stopwatch text-yellow-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">及早终止</h4>
                                    <p class="mt-1 text-gray-600">尽早使用 <code class="bg-gray-200 px-1 py-0.5 rounded">findFirst()</code>, <code class="bg-gray-200 px-1 py-0.5 rounded">anyMatch()</code> 等短路操作提高性能</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-purple-100 rounded-full p-2">
                                    <i class="fas fa-users-cog text-purple-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">注意并发问题</h4>
                                    <p class="mt-1 text-gray-600">在并行流中避免操作共享的可变数据</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-blue-100 rounded-full p-2">
                                    <i class="fas fa-infinity text-blue-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">谨慎使用无限流</h4>
                                    <p class="mt-1 text-gray-600">确保及早终止或限制元素数量，避免内存溢出</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-green-100 rounded-full p-2">
                                    <i class="fas fa-tools text-green-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">选择合适的方法</h4>
                                    <p class="mt-1 text-gray-600">根据需求选择合适的 <code class="bg-gray-200 px-1 py-0.5 rounded">filter</code>, <code class="bg-gray-200 px-1 py-0.5 rounded">map</code>, <code class="bg-gray-200 px-1 py-0.5 rounded">reduce</code> 等方法</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <div class="flex-shrink-0 bg-indigo-100 rounded-full p-2">
                                    <i class="fas fa-project-diagram text-indigo-500"></i>
                                </div>
                                <div class="ml-4">
                                    <h4 class="text-lg font-semibold text-gray-800">理解操作类型</h4>
                                    <p class="mt-1 text-gray-600">区分中间操作和终端操作，合理组织代码</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Diagram -->
        <section class="mb-20">
            <div class="bg-white rounded-xl p-8 card-hover">
                <h3 class="text-2xl font-semibold mb-6 text-center text-indigo-600">Stream API 核心概念关系图</h3>
                <div class="mermaid">
                    flowchart TD
                        A[Stream API] --> B[创建方式]
                        A --> C[操作类型]
                        A --> D[执行方式]
                        A --> E[注意事项]
                        
                        B --> B1[集合.stream()]
                        B --> B2[Arrays.stream()]
                        B --> B3[Stream.of()]
                        B --> B4[Stream.generate()]
                        B --> B5[Stream.iterate()]
                        B --> B6[Files.lines()]
                        
                        C --> C1[中间操作]
                        C --> C2[终端操作]
                        
                        C1 --> C11[filter]
                        C1 --> C12[map]
                        C1 --> C13[sorted]
                        C1 --> C14[distinct]
                        C1 --> C15[limit]
                        
                        C2 --> C21[forEach]
                        C2 --> C22[collect]
                        C2 --> C23[reduce]
                        C2 --> C24[count]
                        C2 --> C25[anyMatch]
                        
                        D --> D1[串行流]
                        D --> D2[并行流]
                        D2 --> D21[parallel()]
                        
                        E --> E1[避免修改源数据]
                        E --> E2[及早终止]
                        E --> E3[避免副作用]
                        E --> E4[谨慎使用并行]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center">
                <h3 class="text-2xl font-bold mb-4">技术小馆</h3>
                <p class="text-gray-400">分享前沿技术，探索编程艺术</p>
                <div class="mt-6">
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-200">http://www.yuque.com/jtostring</a>
                </div>
                <div class="mt-8 flex justify-center space-x-6">
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```